/* 
 * File:   Lesson3.cpp
 * Author: jose
 * 
 * Created on March 29, 2012, 1:15 PM
 */

#include "Lesson3.h"
#include <iostream>
#include <SdlUtils.h>

using namespace std;

Lesson3::Lesson3() {
}

Lesson3::Lesson3(const Lesson3& orig) {
}

Lesson3::~Lesson3() {
}

void Lesson3::SayHello(){
    cout << "Hello World from Lesson3 " << endl;
}

bool Lesson3::init()
{
    //Initialize all SDL subsystems
    if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
    {
        return false;
    }

    //Set up the screen
    screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );

    //If there was an error in setting up the screen
    if( screen == NULL )
    {
        return false;
    }

    //Set the window caption
    SDL_WM_SetCaption( "PNG test", NULL );

    //If everything initialized fine
    return true;
}

int Lesson3::Run(){
      //Initialize
    if( init() == false )
    {
        return 1;
    }

    //Load the image
    message = SdlUtils::loadImage( "look.png" );

    //If there was a problem in loading the image
    if( message == NULL )
    {
        cout << "Falhou aqui";
        return 1;
    }

    //Apply the surface to the screen
    SdlUtils::applySurface(0, 0, message, screen );

    //Update the screen
    if( SDL_Flip( screen ) == -1 )
    {
        return 1;
    }

    //Wait 2 seconds
    SDL_Delay( 2000 );

    //Free the surface
    SDL_FreeSurface( message );

    //Quit SDL
    SDL_Quit();

    return 0;
}